home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: Greatest Hits 1996 / Amiga Games: Greatest Hits 1996.iso / archive / userbox / publicdomain / picturemenu.lha / PictureMenu / Src / PictureMenu.e < prev    next >
Text File  |  1996-04-09  |  7KB  |  320 lines

  1. /*    PictureMenu  v1.3  */
  2. /*            by         */
  3. /*   Pawel 2P Pijanowski */
  4.  
  5.  
  6. MODULE 'intuition/intuition'
  7. MODULE 'intuition/screens'
  8. MODULE 'exec/ports'
  9. MODULE 'exec/nodes'
  10. MODULE 'exec/tasks'
  11. MODULE 'graphics/text'
  12. MODULE 'diskfont'
  13. MODULE 'tools/file'
  14.  
  15. OBJECT pm
  16.     nextpm
  17.     adres_miwb
  18.     adres_itwb
  19.  
  20.     mi_nextitem
  21.     mi_leftedge:INT
  22.     mi_topedge:INT
  23.     mi_width:INT
  24.     mi_height:INT
  25.     mi_flags:INT
  26.     mi_mutualexclude
  27.     mi_itemfill
  28.     mi_selectfill
  29.     mi_command:CHAR
  30.     mi_kludgefill00:CHAR
  31.     mi_subitem
  32.     mi_nextselect:INT
  33.  
  34.     itwb_frontpen:CHAR
  35.     itwb_backpen:CHAR
  36.     itwb_drawmode:CHAR
  37.     itwb_kludgefill00:CHAR
  38.     itwb_leftedge:INT
  39.     itwb_topedge:INT
  40.     itwb_itextfont
  41.     itwb_itext
  42.     itwb_nexttext
  43.  
  44.     itm1_frontpen:CHAR
  45.     itm1_backpen:CHAR
  46.     itm1_drawmode:CHAR
  47.     itm1_kludgefill00:CHAR
  48.     itm1_leftedge:INT
  49.     itm1_topedge:INT
  50.     itm1_itextfont
  51.     itm1_itext
  52.     itm1_nexttext
  53.  
  54.     m1_char:CHAR
  55.     m1_zero:CHAR
  56.  
  57.     itm2_frontpen:CHAR
  58.     itm2_backpen:CHAR
  59.     itm2_drawmode:CHAR
  60.     itm2_kludgefill00:CHAR
  61.     itm2_leftedge:INT
  62.     itm2_topedge:INT
  63.     itm2_itextfont
  64.     itm2_itext
  65.     itm2_nexttext
  66.  
  67.     m2_char:CHAR
  68.     m2_zero:CHAR
  69.  
  70. ENDOBJECT
  71.  
  72. DEF pm_first
  73. DEF pm_prev:PTR TO pm
  74. DEF m_pm:PTR TO pm
  75. DEF taskname[10]:STRING
  76. DEF prefsname[30]:STRING
  77. DEF m_textattr:textattr
  78. DEF scr:PTR TO screen
  79. DEF error=FALSE,errormes[30]:STRING
  80. DEF m_textfont
  81. DEF font[20]:STRING
  82. DEF it_nic:intuitext
  83.  
  84. /*==================================================*/
  85.  
  86. PROC main()
  87. DEF win:PTR TO window
  88. DEF firsttime=FALSE
  89. DEF it:PTR TO intuitext
  90. DEF resetwbmi:PTR TO menuitem
  91. DEF mysz
  92.     StrCopy(taskname,'Workbench',ALL)
  93.     UpperStr(taskname)
  94.  
  95.     StrCopy(prefsname,'ENV:PicM_Workbench.prefs',ALL)
  96.  
  97.     IF win:=OpenW(0,0,1,1,$200,256,'',NIL,1,NIL)
  98.         scr:=win.wscreen
  99.         CloseW(win)
  100.         REPEAT
  101.             IF firsttime THEN restore()
  102.             firsttime:=TRUE
  103.             resetwbmi:=modifymenu()
  104.             it:=resetwbmi.itemfill
  105.             it:=it.nexttext
  106.             REPEAT
  107.                 Delay(50)
  108.             UNTIL it.itextfont<>m_textattr
  109.             mysz:=Mouse()
  110.         UNTIL error OR mysz=%1
  111.         restore()
  112.     ELSE
  113.         seterror('OpenWindow()')
  114.     ENDIF
  115.     IF error THEN WriteF('\nPictureMenu ERROR... \s\n',errormes) ELSE WriteF('PictureMenu: "bye bye !!"\n')
  116.     IF diskfontbase THEN CloseLibrary(diskfontbase)
  117. ENDPROC
  118.  
  119. PROC modifymenu()
  120. DEF fh
  121. DEF resetwbmi:PTR TO menuitem
  122. DEF mm:PTR TO menu
  123. DEF firstmm
  124. DEF mi:PTR TO menuitem
  125. DEF txinmn[20]:STRING
  126. DEF itemtext[20]:STRING
  127. DEF delta,licznik,value
  128. DEF wb_intuitext:PTR TO intuitext
  129. DEF m1_intuitext:PTR TO intuitext
  130. DEF m2_intuitext:PTR TO intuitext
  131. DEF wb_textattr:PTR TO textattr
  132. DEF m_image:PTR TO image
  133.     resetwbmi:=0
  134.     IF fh:=Open(prefsname,OLDFILE)
  135.         setfont(fh)
  136.         IF error=FALSE
  137.             mm:=setmenu(0)
  138.             IF mm
  139.                 firstmm:=mm
  140.                 pm_prev:=0
  141.                 ReadStr(fh,txinmn)
  142.                 WHILE mm<>0
  143.                     delta:=0
  144.                     licznik:=delta
  145.                     mi:=mm.firstitem
  146.                     WHILE mi<>0
  147.                         IF (m_pm:=AllocMem(SIZEOF pm,2))
  148.                             IF pm_prev=0 THEN pm_first:=m_pm ELSE pm_prev.nextpm:=m_pm
  149.                             pm_prev:=m_pm
  150.                             m_pm.nextpm:=0
  151.                             m_pm.adres_miwb:=mi
  152.                             m_pm.adres_itwb:=mi.itemfill
  153.                             CopyMem(m_pm.adres_miwb,(m_pm+12),34)
  154.                             CopyMem(m_pm.adres_itwb,(m_pm+46),20)
  155.                             IF (mi.flags AND %10)
  156.                                 wb_intuitext:=mi.itemfill
  157.                                 StrCopy(itemtext,wb_intuitext.itext)
  158.                                 UpperStr(itemtext)
  159.                                 UpperStr(txinmn)
  160.                                     
  161.                                 m1_intuitext:=m_pm+66
  162.                                 m2_intuitext:=m_pm+88
  163.                                 CopyMem(wb_intuitext,m1_intuitext,20)
  164.                                 CopyMem(wb_intuitext,m2_intuitext,20)
  165.  
  166.                                 m1_intuitext.itextfont:=m_textattr
  167.                                 m2_intuitext.itextfont:=m_textattr
  168.  
  169.                                 m1_intuitext.drawmode:=1
  170.                                 m1_intuitext.backpen:=1
  171.                                 m1_intuitext.frontpen:=0
  172.                                 m2_intuitext.drawmode:=1
  173.                                 m2_intuitext.backpen:=1
  174.                                 m2_intuitext.frontpen:=0
  175.                                 wb_intuitext.drawmode:=0
  176.                                 wb_intuitext.backpen:=0
  177.                                 wb_intuitext.frontpen:=1
  178.  
  179.                                 wb_intuitext.nexttext:=m1_intuitext
  180.                                 m1_intuitext.nexttext:=it_nic
  181.                                 m2_intuitext.nexttext:=it_nic
  182.                                 mi.selectfill:=m2_intuitext
  183.                                 mi.itemfill:=wb_intuitext
  184.  
  185.                                 mi.flags:=(mi.flags OR HIGHIMAGE) AND (Not(HIGHCOMP))
  186.                                 IF StrCmp(wb_intuitext.itext,'ResetWB',7) THEN resetwbmi:=mi
  187.  
  188.                                 wb_intuitext.leftedge:=wb_intuitext.leftedge+m_textattr.ysize+16
  189.                                 mi.width:=mi.width+m_textattr.ysize+16
  190.                                 wb_textattr:=wb_intuitext.itextfont
  191.                                 IF m_textattr.ysize > wb_textattr.ysize
  192.                                     mi.height:=m_textattr.ysize+4
  193.                                     wb_intuitext.topedge:=(wb_intuitext.topedge+((mi.height-wb_textattr.ysize)/2))
  194.                                     mi.topedge:=((licznik*(mi.height+2))-delta)
  195.                                 ENDIF
  196.                                 m1_intuitext.topedge:=m1_intuitext.topedge+1
  197.                                 m2_intuitext.topedge:=m2_intuitext.topedge+1
  198.                                 IF (StrCmp(itemtext,txinmn,StrLen(txinmn))) AND (StrLen(txinmn)<>0)    
  199.                                     value:=readvalue(fh)
  200.                                     m_pm.m1_char:=value
  201.                                     value:=readvalue(fh)
  202.                                     m_pm.m2_char:=value
  203.                                     ReadStr(fh,txinmn)
  204.                                     ReadStr(fh,txinmn)
  205.                                 ELSE
  206.                                     m_pm.m1_char:=32
  207.                                     m_pm.m2_char:=32
  208.                                 ENDIF
  209.                                 m_pm.m1_zero:=0
  210.                                 m_pm.m2_zero:=0
  211.                                 m1_intuitext.itext:=m_pm+86
  212.                                 m2_intuitext.itext:=m_pm+108
  213.                             ELSE
  214.                                 mi.topedge:=(licznik*(m_textattr.ysize+6))-delta
  215.                                 m_image:=mi.itemfill
  216.                                 mi.width:=mi.width+m_textattr.ysize+16
  217.                                 m_image.leftedge:=m_image.leftedge+m_textattr.ysize+16
  218.                                 delta:=delta+m_textattr.ysize-m_image.height
  219.                             ENDIF
  220.                             INC licznik
  221.                             mi:=mi.nextitem    
  222.                         ELSE
  223.                             seterror('AllocMem()')
  224.                         ENDIF
  225.                     ENDWHILE
  226.                     mm:=mm.nextmenu
  227.                 ENDWHILE
  228.                 CopyMem(resetwbmi.itemfill,it_nic,20)
  229.                 it_nic.itext:=''
  230.                 it_nic.nexttext:=0
  231.                 setmenu(firstmm)
  232.             ELSE
  233.                 seterror('I can`t find WB task.')
  234.             ENDIF
  235.         ENDIF
  236.         Close(fh)
  237.     ELSE
  238.         seterror('Open("ENV:PicM_Workbench.prefs")')
  239.     ENDIF
  240. ENDPROC resetwbmi
  241.  
  242. PROC restore()
  243. DEF pm_next
  244. DEF mm
  245.     mm:=setmenu(0)
  246.     IF m_textfont THEN CloseFont(m_textfont)
  247.     m_pm:=pm_first
  248.     WHILE m_pm<>0
  249.         CopyMem(m_pm+16,m_pm.adres_miwb+4,30)
  250.         CopyMem(m_pm+46,m_pm.adres_itwb,20)
  251.         pm_next:=m_pm.nextpm
  252.         FreeMem(m_pm,SIZEOF pm)
  253.         m_pm:=pm_next
  254.     ENDWHILE
  255.     IF mm THEN setmenu(mm)
  256.     pm_first:=0
  257. ENDPROC
  258.  
  259.  
  260. /*===================================================*/
  261. PROC seterror(tekst)
  262.     error:=TRUE
  263.     StrCopy(errormes,tekst,ALL)
  264. ENDPROC
  265.  
  266. PROC setfont(fh)
  267. DEF sizestr[3]:STRING
  268.     IF ReadStr(fh,font)=-1 THEN seterror('font') 
  269.     IF ReadStr(fh,sizestr)=-1 THEN seterror('size font') 
  270.     m_textattr.name:=font
  271.     m_textattr.ysize:=Val(sizestr)
  272.     m_textattr.style:=0
  273.     m_textattr.flags:=FPF_DESIGNED 
  274.     ReadStr(fh,sizestr)
  275.     IF diskfontbase=0 THEN diskfontbase:=OpenLibrary('diskfont.library',NIL)
  276.     IF diskfontbase
  277.         m_textfont:=OpenDiskFont(m_textattr)
  278.         IF m_textfont=0
  279.             seterror('OpenDiskFont()')
  280.         ENDIF
  281.     ELSE
  282.         seterror('OpenLibrary("diskfont.library")')
  283.     ENDIF
  284.     
  285. ENDPROC
  286.  
  287. PROC setmenu(mmm)
  288. DEF actwin:PTR TO window
  289. DEF actnodename[10]:STRING
  290. DEF mojmsgport:PTR TO mp
  291. DEF mojnode:PTR TO ln
  292. DEF mojtask:PTR TO tc
  293. DEF actmenu:PTR TO menu
  294.     actmenu:=mmm
  295.     actwin:=scr.firstwindow
  296.     WHILE (actwin<>0)
  297.         mojmsgport:=actwin.userport
  298.         mojtask:=mojmsgport.sigtask
  299.         mojnode:=mojtask.ln
  300.         StrCopy(actnodename,mojnode.name,ALL)
  301.         UpperStr(actnodename)
  302.         IF StrCmp(actnodename,taskname,StrLen(taskname))
  303.             IF mmm<>0
  304.                 SetMenuStrip(actwin,mmm)
  305.             ELSE
  306.                 actmenu:=actwin.menustrip
  307.                 ClearMenuStrip(actwin)
  308.             ENDIF
  309.         ENDIF
  310.         actwin:=actwin.nextwindow        
  311.     ENDWHILE
  312. ENDPROC actmenu
  313.  
  314. PROC readvalue(filehandle)
  315. DEF m_string[20]:STRING
  316. DEF value
  317.     IF ReadStr(filehandle,m_string)=-1 THEN value:=32
  318.     value:=Val(m_string)
  319. ENDPROC value
  320.